<?php

namespace App\Kuafu\CouponPackage\Validate;

use App\Kuafu\Activity\Enum\ActivityEnum;
use App\Kuafu\Coupon\Model\CouponModel;
use App\Kuafu\CouponPackage\Enum\CouponPackageEnum;
use App\Kuafu\Base\Validate\BaseValidate;
use Illuminate\Support\Facades\Validator;

class CouponPackageMappingValidate extends BaseValidate
{

    public  static function getRules()
    {
        return [
            'couponInfo'           => ['required', 'array', function ($attribute, $value, $fail) {
                if(! empty($value)){
                    foreach ($value as $item){
                        if($item['id'] <= 0 || $item['num'] <=0){
                            $fail('The '.$attribute.' is invalid.');
                            break;
                        }
                    }
                }else{
                    $fail('The '.$attribute.' is invalid.');
                }
            }],
        ];
    }



    /**
     * @param array $requestParams
     * @return array
     */
    public static function insertValidate(array  $requestParams): array
    {
        return [
            self::getRequestParams($requestParams, array_keys(self::getRules())),
            self::validateCheck($requestParams, self::getRules(), [])];
    }

}
